using System;
using System.Reflection.Emit;
using Pine.Core;
using Pine.SourceParser.Tree;

namespace Pine.CodeGen
{
	public static class ArrayAccessExpressionCodeGenerator
	{
		public static void GenerateBytecode(Context ctx, Expression expr, LocalBuilder lb) {
			ArrayAccessExpression ar = (ArrayAccessExpression) expr;
			ar.left.GenerateBytecode(ctx, lb);
			LocalBuilder rlb = ctx.il.DeclareLocal(typeof(Value));
			ar.right.GenerateBytecode(ctx, rlb);
			ctx.il.Emit(OpCodes.Ldloc, lb);
			ctx.il.Emit(OpCodes.Ldloc, rlb);
			ctx.il.Emit(OpCodes.Callvirt, typeof(Value).GetMethod("GetArrayElement"));
			ctx.il.Emit(OpCodes.Stloc, lb);
		}
	}
}

